function [data] = whiten(data)

data = arrayfun(@whitenInstance, data);
end

function [data] = whitenInstance(data)
if ~isempty(data.cam_id)
    disp(['WhitenInstance: ', num2str(data.cam_id)]);
    pos = size(data.ppl_rects,1);
    neg = size(data.bg_rects,1);
    matrix = [data.ppl_hogs; data.bg_hogs];
    % matrix = matrix';
    C = cov(matrix);
    M = mean(matrix);
    [V,D] = eig(C);
    P = V*diag(1./sqrt(diag(D)+0.1))*V';
    W = bsxfun(@minus, matrix,M)*P;
    %W=W';
    data.ppl_hogs = W(1:pos,:);
    data.bg_hogs = W(pos+1:end,:);
end
end